import type { Recordable } from '@vben/types';

import { requestClient } from '#/api/request';

export namespace SystemRoleApi {
  export interface SystemRole {
    [key: string]: any;
    id: string;
    code: string;
    name: string;
    permissions: string[];
    desc?: string;
    status: 0 | 1;
  }
}

/**
 * 获取角色分页数据
 */
async function getRoleList(params: Recordable<any>) {
  return requestClient.get<Array<SystemRoleApi.SystemRole>>('/v1/role/pages', {
    params,
  });
}

/**
 * 获取角色列表数据
 */
async function getAllRoleList(params: Recordable<any>) {
  return requestClient.get<Array<SystemRoleApi.SystemRole>>('/v1/role/list', {
    params,
  });
}

/**
 * 创建角色
 * @param data 角色数据
 */
async function createRole(data: Omit<SystemRoleApi.SystemRole, 'id'>) {
  return requestClient.post('/v1/role/create', data);
}

/**
 * 更新角色
 *
 * @param id 角色 ID
 * @param data 角色数据
 */
async function updateRole(id: string, data: Partial<SystemRoleApi.SystemRole>) {
  return requestClient.post(`/v1/role/update`, { ...data, id });
}

/**
 * 删除角色
 * @param id 角色 ID
 */
async function deleteRole(id: string) {
  return requestClient.delete(`/v1/role/delete?role_id=${id}`);
}

export { createRole, deleteRole, getAllRoleList, getRoleList, updateRole };
